package cn.edu.sdjzu.xg.kcsj.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ListHelper {
    // 逗号隔开的字符串转Integer数组
    public static List<Integer> stringToIntegerList(String str){
        List<String> stringList = Arrays.asList(str.split("\\,"));
        List<Integer> integerList = new ArrayList<>();
        for (String s:stringList){
            int i = Integer.parseInt(s);
            integerList.add(i);
        }
        return integerList;
    }

    // Integer转逗号分隔的字符串
    public static String listToString(List<Integer> list){
        StringBuffer sb = new StringBuffer();
        for (int i = 0;i < list.size();i++){
            sb.append(list.get(0));
            if ((i + 1) != list.size()){
                sb.append(",");
            }
        }
        return sb.toString();
    }
}
